#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
class Solution {
public:
    int mostFrequentEven(vector<int>& nums) {
        unordered_map<int,int>map;
        int tmp=-1;
        int ans=INT_MAX;
        for(auto num:nums)
        {
            map[num]++;
            if(tmp<=map[num]&&num%2==0)
            {
                if(tmp==map[num])
                    ans=min(num,ans);
                else ans=num;
                tmp=map[num];
                
            }
        }
        return ans==INT_MAX?-1:ans;
    }
};